package com.example.administrator.gynews.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.example.administrator.gynews.MainActivity;
import com.example.administrator.gynews.R;
import com.example.administrator.gynews.adapter.ClassMateListVIewAdapter;
import com.example.administrator.gynews.bean.ClassMate;
import com.example.administrator.gynews.bean.StudentInfo;
import com.google.gson.Gson;

import org.json.JSONObject;

/**
 * Created by Administrator on 2019/9/26.
 */

public class StudentInfoActivity extends AppCompatActivity {

    private TextView stuId;
    private TextView stuName;
    private TextView stuClass;
    private TextView stuTelephonenum;
    private TextView stuEmail;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.studentinfo_activity);
        Intent intent = getIntent();
        String stuId = intent.getStringExtra("id");
        initData(stuId);
        initView();


    }

    private void initView() {
        stuId = (TextView) findViewById(R.id.student_id);
        stuName = (TextView) findViewById(R.id.student_name);
        stuClass = (TextView) findViewById(R.id.student_class);
        stuTelephonenum = (TextView) findViewById(R.id.student_telephonenum);
        stuEmail = (TextView) findViewById(R.id.student_email);


    }

    private void initData(String id) {
        String url = "http://10.1.63.140:8090/freshmenapp/classmate/findone/"+id;
        RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
        final Gson gson = new Gson();
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                StudentInfo studentInfo = gson.fromJson(jsonObject.toString(),StudentInfo.class);
                stuId.setText(studentInfo.getData().getId()+"");
                stuName.setText(studentInfo.getData().getName()+"");
                stuClass.setText(studentInfo.getData().getClassName()+"");
                stuTelephonenum.setText(studentInfo.getData().getPhone()+"");
                stuEmail.setText(studentInfo.getData().getEmail()+"");

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Toast.makeText(StudentInfoActivity.this, "网络错误", Toast.LENGTH_SHORT).show();
            }
        });
        requestQueue.add(jsonObjectRequest);
    }
}
